package com.dxj.dog.vaccine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dxj.dog.admin.service.IDogAdminService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dxj.common.annotation.Log;
import com.dxj.common.core.controller.BaseController;
import com.dxj.common.core.domain.AjaxResult;
import com.dxj.common.enums.BusinessType;
import com.dxj.dog.vaccine.domain.DogVaccine;
import com.dxj.dog.vaccine.service.IDogVaccineService;
import com.dxj.common.utils.poi.ExcelUtil;
import com.dxj.common.core.page.TableDataInfo;

/**
 * 疫苗记录Controller
 *
 * @author 杜晓俊
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/dog/vaccine")
public class DogVaccineController extends BaseController {
    @Autowired
    private IDogVaccineService dogVaccineService;

    /**
     * 查询疫苗记录列表
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:list')")
    @GetMapping("/list")
    public TableDataInfo list(DogVaccine dogVaccine) {
        startPage();
        List<DogVaccine> list = dogVaccineService.selectDogVaccineList(dogVaccine);
        return getDataTable(list);
    }

    /**
     * 导出疫苗记录列表
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:export')")
    @Log(title = "疫苗记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DogVaccine dogVaccine) {
        List<DogVaccine> list = dogVaccineService.selectDogVaccineList(dogVaccine);
        ExcelUtil<DogVaccine> util = new ExcelUtil<DogVaccine>(DogVaccine.class);
        util.exportExcel(response, list, "疫苗记录数据");
    }

    /**
     * 获取疫苗记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:query')")
    @GetMapping(value = "/{vaccineId}")
    public AjaxResult getInfo(@PathVariable("vaccineId") Long vaccineId) {
        return AjaxResult.success(dogVaccineService.selectDogVaccineByVaccineId(vaccineId));
    }

    /**
     * 新增疫苗记录
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:add')")
    @Log(title = "疫苗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DogVaccine dogVaccine) {
        return toAjax(dogVaccineService.insertDogVaccine(dogVaccine));
    }

    /**
     * 修改疫苗记录
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:edit')")
    @Log(title = "疫苗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DogVaccine dogVaccine) {
        return toAjax(dogVaccineService.updateDogVaccine(dogVaccine));
    }

    /**
     * 删除疫苗记录
     */
    @PreAuthorize("@ss.hasPermi('dog:vaccine:remove')")
    @Log(title = "疫苗记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{vaccineIds}")
    public AjaxResult remove(@PathVariable Long[] vaccineIds) {
        return toAjax(dogVaccineService.deleteDogVaccineByVaccineIds(vaccineIds));
    }
}
